<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('创建时间')">
              <j-date
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('机台名称')">
              <j-dict-select-tag
                :placeholder="$t('请选择机台名称')"
                v-model="queryParam.gameId"
                dictCode="bis_game,name,id"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('机位号')">
                <a-input :placeholder="$t('请输入机位号')" v-model="queryParam.machineNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('处理时间')">
                <j-date
                  :show-time="true"
                  date-format="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择开始时间')"
                  class="query-group-cust"
                  v-model="queryParam.solveTime_begin"
                ></j-date>
                <span class="query-group-split-cust"></span>
                <j-date
                  :show-time="true"
                  date-format="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择结束时间')"
                  class="query-group-cust"
                  v-model="queryParam.solveTime_end"
                ></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('处理人')">
                <j-dict-select-tag
                  :placeholder="$t('请选择处理人')"
                  v-model="queryParam.solveBy"
                  dictCode="sys_user,realname,realname"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('状态')">
                <j-dict-select-tag
                  :placeholder="$t('请选择状态')"
                  v-model="queryParam.state"
                  dictCode="bis_device_notice.state"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input :placeholder="$t('请输入会员手机号/卡号')" v-model="queryParam.memberInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('备注')">
                <j-input v-model="queryParam.remark"></j-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
              }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'BisDeviceNoticeController:export'" type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('服务通知'))">{{
        $t('导出')
      }}</a-button>
      <a-button v-has="'BisDeviceNoticeController:edit'" type="primary" @click="clickBatchEdit">{{ $t('批量处理') }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
        :rowSelection="rowSelection"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-has="'BisDeviceNoticeController:edit'" v-if="record.state == 0" @click="handleEdit(record)">{{ $t('处理') }}</a>
        </span>
      </a-table>
    </div>

    <bis-device-notice-modal ref="modalForm" @ok="modalFormOk"></bis-device-notice-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import {httpAction} from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BisDeviceNoticeModal from './modules/BisDeviceNoticeModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'BisDeviceNoticeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BisDeviceNoticeModal,
  },
  data() {
    return {
      description: '服务通知管理页面',
      // 表头
      columns: [
        {
          title: this.$t('创建时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('通知类型'),
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('机台名称'),
          align: 'center',
          dataIndex: 'gameId_dictText',
        },
        {
          title: this.$t('机位号'),
          align: 'center',
          dataIndex: 'machineNo',
        },
        {
          title: this.$t('会员手机号'),
          align: 'center',
          dataIndex: 'memberPhone',
        },
        {
          title: this.$t('会员卡号'),
          align: 'center',
          dataIndex: 'chipNo',
        },
        {
          title: this.$t('问题描述'),
          align: 'center',
          dataIndex: 'problem',
          customCell:(t,r)=>{
            return {
              style:{
                'min-width': '300px',
                'max-width': '500px',
                'white-space': 'pre-wrap',
                'word-break': 'break-all'
              }
            }
          }
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('处理人'),
          align: 'center',
          dataIndex: 'solveBy',
        },
        {
          title: this.$t('处理时间'),
          align: 'center',
          dataIndex: 'solveTime',
        },
        {
          title: this.$t('备注'),
          align: 'center',
          dataIndex: 'remark',
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/device/bisDeviceNotice/list',
        delete: '/device/bisDeviceNotice/delete',
        deleteBatch: '/device/bisDeviceNotice/deleteBatch',
        exportXlsUrl: '/device/bisDeviceNotice/exportXls',
        importExcelUrl: 'device/bisDeviceNotice/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    rowSelection() {
      let _this = this
      const { selectedRowKeys } = this
      return {
        selectedRowKeys,
        onChange: (selectedRowKeys, selectionRows) => {
          _this.onSelectChange(selectedRowKeys, selectionRows)
        },
        getCheckboxProps: (record) => ({
          props: {
            // 全部默认禁止选中
            // disabled: true,
            // 某几项默认禁止选中(R: 当state等于1时)
            disabled: record.state == 1, // 某几项默认选中(R: 当state等于1时) // defaultChecked: record.state == 1,
          },
        }),
      }
    },
  },
  methods: {
    clickBatchEdit() {
      let that=this
      if (that.selectedRowKeys.length > 0) {
        that.$confirm({
          content: that.$t('您确定要对选中的通知进行处理吗？'),
          okText: that.$t("确定"),
          cancelText: that.$t("取消"),
          onOk: () => {
            let httpurl = '/device/bisDeviceNotice/editBatch'
            let method = 'post'
            let query = {
              ids : that.selectedRowKeys.join(',')
            }
            httpAction(httpurl, query, method)
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.searchQuery()
                } else {
                  that.$message.warning(res.message)
                }
              })
          },
        })
      } else {
        that.$message.warning(that.$t('请先选择要处理的记录'))
      }
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'datetime', value: 'createTime', text: this.$t('创建时间') })
      fieldList.push({ type: 'string', value: 'gameId', text: this.$t('机台名称'), dictCode: 'bis_game,name,id' })
      fieldList.push({ type: 'int', value: 'machineNo', text: this.$t('机位号'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'memberPhone', text: this.$t('会员手机号'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'chipNo', text: this.$t('会员卡号'), dictCode: '' })
      fieldList.push({ type: 'string', value: 'problem', text: this.$t('问题描述'), dictCode: '' })
      fieldList.push({ type: 'int', value: 'state', text: this.$t('状态'), dictCode: 'bis_device_notice.state' })
      fieldList.push({
        type: 'string',
        value: 'solveBy',
        text: this.$t('处理人'),
        dictCode: 'sys_user,realname,realname',
      })
      fieldList.push({ type: 'datetime', value: 'solveTime', text: this.$t('处理时间') })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>